package com.study.rabbitmq;

import com.rabbitmq.client.AMQP;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

public class MessagePersistent {

    public static void main(String[] args) throws Exception {
        ConnectionFactory connectionFactory = new ConnectionFactory();
        connectionFactory.setUri("amqp://root:123456@192.168.181.131:5672/%2f");

        Connection connection = connectionFactory.newConnection();
        Channel channel = connection.createChannel();

        channel.queueDeclare("queue.persistent",true,false,false,null);
        channel.exchangeDeclare("exchange.persistent","direct",true,false,false,null);
        channel.queueBind("queue.persistent","exchange.persistent","routingkey.persistent");

        AMQP.BasicProperties properties = new AMQP.BasicProperties().builder()
                .deliveryMode(2)
                .build();
        String msg = "hello world";
        channel.basicPublish("exchange.persistent","routingkey.persistent",properties,msg.getBytes());

        channel.close();
        connection.close();
    }


}
